//新增Array的indexOf方法
Array.prototype.indexOf = function(val) {
	for (var i = 0; i < this.length; i++) {
		if (this[i] == val)
			return i;
	}
	return -1;
};

//新增Array的remove方法
Array.prototype.remove = function(val) {
	var index = this.indexOf(val);
	if (index > -1) {
		this.splice(index, 1);
	}
};


//转换对象的属性名
function transObject(o){
	var n = {};
	n['id'] = o['rsID'];
	n['text'] = o['rsName'];
	n['desc'] = o['rsDesc'];
	n['url'] = o['rsURL'];
	n['type'] = o['rsType'];
	n['level'] = o['rsLevel'];
	n['pid'] = o['rsPID'];
	if(o['children'] && o['children'].length>0){
		n['children'] = o['children'];
	}
	return n;
}

//构建树data
function buildTreeData(list, pid) {
	var tmp = [];
	for (var i = 0; i < list.length; i++) {
		var item = list[i];
		if (item['rsPID'] == pid) {
			list.remove(item);
			i--;
			item.children = buildTreeData(list, item['rsID']);
			item = transObject(item);//转换对象的属性名
			tmp.push(item);
		}
	}
	return tmp;
}
	
//var time1 = new Date().format("yyyy-MM-dd");
//var time2 = new Date().format("yyyy-MM-dd HH:mm:ss");  
Date.prototype.format = function (fmt) { //author: meizz 
  var o = {
      "M+": this.getMonth() + 1, //月份 
      "d+": this.getDate(), //日 
      "h+": this.getHours(), //小时 
      "m+": this.getMinutes(), //分 
      "s+": this.getSeconds(), //秒 
      "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
      "S": this.getMilliseconds() //毫秒 
  };
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  for (var k in o)
  if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  return fmt;
}